package nio.traditionalcopy;

import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.Socket;

/**
 * 传统IO
 * 客户端
 */
public class OldIOClient {

	public static void main(String[] args) throws Exception {
		Socket socket = new Socket("localhost", 7001);
		// 需要拷贝的大文件
		String fileName = "C:\\Users\\chenyuan\\Desktop\\尚硅谷Netty教程\\Netty相关资料\\资料\\protoc-3.6.1-win32.zip";
		InputStream inputStream = new FileInputStream(fileName);

		DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());

		byte[] buffer = new byte[4096];
		long readCount;
		long total = 0;

		long startTime = System.currentTimeMillis();

		while ((readCount = inputStream.read(buffer)) >= 0) {
			total += readCount;
			dataOutputStream.write(buffer);
		}

		System.out.println("发送总字节数： " + total + ", 耗时： " + (System.currentTimeMillis() - startTime));

		dataOutputStream.close();
		socket.close();
		inputStream.close();
	}
}
